<template>
  <div>
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
      style="text-align: left"
    >
      <el-form-item>
        <el-form-item label="月卡编号">
          <el-input
            v-model="formInline.number"
            placeholder="月卡编号"
          ></el-input>
        </el-form-item>
        <el-form-item label="车牌号">
          <el-input v-model="formInline.plate" placeholder="车牌号"></el-input>
        </el-form-item>
        <el-form-item label="车位类型">
          <el-select v-model="formInline.type" placeholder="请选择车位类型">
            <el-option label="请选择" value=""></el-option>
            <el-option label="普通车位" value="1"></el-option>
            <el-option label="内部车位" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="月卡状态">
          <el-select v-model="formInline.state" placeholder="请选择月卡状态">
            <el-option label="请选择" value=""></el-option>
            <el-option label="正常" value="1"></el-option>
            <el-option label="即将过期" value="2"></el-option>
            <el-option label="已过期" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-button
          style="background-color: green; color: white"
          icon="el-icon-search"
          @click="list"
          >查询</el-button
        >
        <el-button style="color: gray" icon="el-icon-refresh">重置</el-button>
        <el-button style="color: orange" icon="el-icon-loading" @click="fantian"
          >查看</el-button
        >
      </el-form-item>
    </el-form>

    <el-dialog width="600px" title="详情信息" :visible.sync="dialogFormVisible">
      <el-form
        ref="form"
        :model="form"
        label-width="180px"
        style="width: 600px; margin: 2px auto"
      >
        <el-form-item label="月卡编号">
          {{ form.number }}
        </el-form-item>
        <el-form-item label="车辆姓名">
          {{ form.name }}
        </el-form-item>
        <el-form-item label="联系电话">
          {{ form.phone }}
        </el-form-item>
        <el-form-item label="车牌号码">
          {{ form.plate }}
        </el-form-item>
        <el-form-item label="开始时间">
          {{ form.begindate }}
        </el-form-item>
        <el-form-item label="到期时间">
          {{ form.expiredate }}
        </el-form-item>
        <el-form-item label="车位类型">
          {{ form.type }}
        </el-form-item>
        <el-form-item label="车位编号">
          {{ form.stall }}
        </el-form-item>
        <el-form-item label="状态">
          {{ form.state }}
        </el-form-item>
      </el-form>
    </el-dialog>

    <template>
      <el-table
        :data="tableData"
        border
        style="width: 100%"
        :row-class-name="tableRowClassName"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="id" label="序号" align="center">
        </el-table-column>
        <el-table-column prop="number" label="月卡编号" align="center">
        </el-table-column>
        <el-table-column prop="name" label="车主姓名" align="center">
        </el-table-column>
        <el-table-column prop="phone" label="联系电话" align="center">
        </el-table-column>
        <el-table-column prop="plate" label="车牌号码" align="center">
        </el-table-column>
        <el-table-column prop="begindate" label="开始时间" align="center">
        </el-table-column>
        <el-table-column prop="expiredate" label="到期时间" align="center">
        </el-table-column>
        <el-table-column prop="type" label="车位类型" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.type == 1">普通车位</span>
            <span v-if="scope.row.type == 2">内部车位</span>
          </template>
        </el-table-column>
        <el-table-column prop="stall" label="车位编号" align="center">
        </el-table-column>
        <el-table-column prop="state" label="状态" align="center">
          <template slot-scope="scope">
            <span style="color: #409eff" v-if="scope.row.state == 1">正常</span>
            <span style="color: #67c23a" v-if="scope.row.state == 2"
              >即将过期</span
            >
            <span style="color: #f56c6c" v-if="scope.row.state == 3"
              >已过期</span
            >
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="formInline.pageIndex"
      :page-sizes="[1, 2, 3, 4]"
      :page-size="formInline.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="countnum"
    >
    </el-pagination>
  </div>
</template>
<script>
import { GetShowMonthcard } from "@/api/Area/Monthcard";
import { GetTotaocount } from "@/api/Area/Monthcard";
export default {
  data() {
    return {
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex === 0) {
          return "warning-row";
        } else if (rowIndex === 2) {
          return "success-row";
        }
        return "";
      },
      tableData: [],
      dialogFormVisible: false,
      multipleSelection: [],
      ids: {},
      //详情
      form: {
        id: "",
        number: "",
        name: "",
        phone: "",
        plate: "",
        begindate: "",
        expiredate: "",
        type: "",
        stall: "",
        state: "",
      },
      //分页查询
      formInline: {
        pageIndex: 1,
        pageSize: 2,
        number: "",
        plate: "",
        type: "",
        state: "",
        /* begindate: "",
        expiredate: "", */
      },
      countnum: 0,
      count: 0,
    };
  },
  created() {
    this.list();
    this.totalcount();
  },
  methods: {
    //显示
    list() {
      GetShowMonthcard(this.formInline).then((res) => {
        this.tableData = res.data.data;
        this.count = res.data.totalCount;
      });
    },
    handleSizeChange(val) {
      this.formInline.pageSize = val;
      this.list();
    },
    handleCurrentChange(val) {
      this.formInline.pageIndex = val;
      this.list();
    },
    totalcount() {
      GetTotaocount().then((res) => {
        this.countnum = res.data;
      });
    },
    //全选/反选
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //查看详情
    fantian() {
      if (this.multipleSelection.length != 1) {
        this.$message.error("请选择一条数据");
        return;
      }
      this.dialogFormVisible = true;
      this.multipleSelection.forEach((res) => {
        this.form = res;
      });
    },
  },
};
</script>
<style>
.el-table .warning-row {
  background: rgb(230, 253, 253);
}

.el-table .success-row {
  background: #f4ebf9;
}
</style>